
import torch
import torch.nn as nn

class RandomModel(nn.Module):
    def __init__(self, text_dim, image_dim, num_classes):
        super().__init__()
        self.text_proj = nn.Linear(text_dim, 512)
        self.image_proj = nn.Linear(image_dim, 512)
        # 初始化参数为随机值
        self.text_proj.weight.data = torch.randn_like(self.text_proj.weight.data)
        self.image_proj.weight.data = torch.randn_like(self.image_proj.weight.data)
    
    def get_text_features(self, texts=None, **kwargs):
        # 模拟文本特征输入
        batch_size = kwargs.get('input_ids', texts).shape[0]
        # 获取模型所在设备
        device = self.text_proj.weight.device
        # 在正确的设备上生成随机特征
        random_text_feat = torch.randn(batch_size, self.text_proj.in_features, device=device)
        return self.text_proj(random_text_feat)
    
    def get_image_features(self, images=None, **kwargs):
        # 模拟图像特征输入
        batch_size = kwargs.get('pixel_values', images).shape[0]
        # 获取模型所在设备
        device = self.image_proj.weight.device
        # 在正确的设备上生成随机特征
        random_image_feat = torch.randn(batch_size, self.image_proj.in_features, device=device)
        return self.image_proj(random_image_feat)

# 评估随机模型
random_model = RandomModel(text_dim=768, image_dim=768, num_classes=1000)
